<?php
/**
 * Created by PhpStorm.
 * User: yzapple
 * Date: 2018/1/8
 * Time: 下午2:05
 */

namespace app\common\model;
use app\common\model\Base;
use think\Db;

class Doctordepartment extends Base
{
    protected $table = "doctor_department";



    protected $base_arr = [
        'table' => 'doctor_department',
        'field' => 'department,is_deleted,comment',
        'primary_key' => 'id'
    ];

    protected $attach_arr =  [


    ];


    /**
     * 获取字段对应的数组
     * */
    public function getDataByMysql(){
        $data = [
            't_name' => $this->table,//必填
            'model' => '部门',//必填
            'department' => '部门名称',
            'comment' => '部门描述',
            'is_deleted' => '{"2":"功能禁用","1":"功能启用","3":"功能删除"}'
        ];
        return $data;
    }


    /**
     * 获取日志的访问方法
     **/
    public static function addDoctordepartmentAdminLog($list_action='',$form_data=[],$userId,$admin_type){
        $model = new Doctordepartment();
        $actionName = strtolower(ACTION_NAME);
        $controller = strtolower(CONTROLLER_NAME);
        $old_data = [];
        $type = '';
        switch($actionName){
            //列表
            case "department":
                Base::save_admin_log($userId, $model, 'check','',[],[],$admin_type);
                break;
            case "add_department":
                $type = 'add';
                if ($model->request->isPost()) {

                }
                break;
            case "edit_department":
                $type = 'edit';
                if ($model->request->isPost()) {
                    $old_data = Base::getOneOldDataByTables($form_data['id'],$model->base_arr,$model->attach_arr);

                }
                break;
            case "del_department":
                $type = 'del';
                if ($model->request->isPost()) {

                    $id = $form_data["id"];
                    Db::execute("update doctor_department set is_deleted=3  where id=?", [ $id]);

                }
                break;
        }


        if($model->request->isPost() ){

            //$model 实例化之后的模型
            //$type 数据的操作类型
            //$form_data  form表单提交之后的表单
            //$url 跳转路径
            //$old_data 原有的数据
            //$attach_arr 附属表单数组
            //$primary_key 基本表单的主键值id
            $result =  Base::operaTable($model,$userId,$type,$form_data,$controller.'/'.$list_action,$old_data,$model->attach_arr,'id',$admin_type);
            return $result;
        }


        return true;


    }






}
